import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import votaciones.*;

/**
 * Servlet implementation class for Servlet: RealizaVotacion
 * 
 */
public class RealizaVotacion extends javax.servlet.http.HttpServlet implements
		javax.servlet.Servlet {
	static final long serialVersionUID = 1L;

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public RealizaVotacion() {
		super();
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		response.setContentType("text/html");
		String nombre = request.getParameter("Votacion");
		if (nombre != null) {
			Votacion v;
			List<Votacion> votaciones = AlmacenVotaciones.getInstance()
					.getVotaciones();
			boolean enc = false;
			Iterator itv = votaciones.iterator();
			while (!enc || itv.hasNext()) {
				Votacion vot = (Votacion) itv.next();
				if (vot.getNombre().equals(nombre)) {
					v = vot;
					enc = true;
				}
			}
			RequestDispatcher d = request.getRequestDispatcher("RealizaVotacion2.jsp");
			
			
				d.forward(request,response);

		} else
			out.println("<html><head>Algo va mal</head>Algo va mal</html>");
	}
}